#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <climits>
#include <unordered_map>
using namespace std;

int main() {
	int N; 
	cin >> N;
	unordered_map<int, int> um;
	for(int n=1; n<=N; ++n){
		int a[6];
		for(int i=0; i<6; ++i) cin >> a[i];
		int val = 0;
		for(int i=0; i<6; ++i) {
			if(a[i]==1) {
				if(i%2==0) 
					val = a[(i+2)%6]*1000 + a[(i+4)%6]*100 + a[(i+3)%6]*10 + a[(i+5)%6];
				else  
					val = a[(i+4)%6]*1000 + a[(i+2)%6]*100 + a[(i+3)%6]*10 + a[(i+1)%6];
				break;
			}
		}

		for(int i=0, tmp = val; i<3; ++i) {
			tmp = tmp/10 + (tmp%10*1000);
			val = min(val, tmp);
		}
		um[val]++;
	}

	vector<int> res;
	for(auto iter : um) res.push_back(iter.second);
	sort(res.begin(), res.end());
	
	cout << res.size() << endl;
	for(int i=res.size()-1; i>=0; --i) cout << res[i] << " ";
	return 0;	
}